package com.github.iot;

import android.app.Application;
import android.content.Context;

import com.github.iot.dao.DaoManager;
import com.github.iot.utils.CommonUtils;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.FormatStrategy;
import com.orhanobut.logger.Logger;
import com.orhanobut.logger.PrettyFormatStrategy;

import cn.wch.uartlib.WCHUARTManager;

/**
 * TODO
 *
 * @Author: 梁声洪
 * @Date: 2019/12/7 0:59
 * @Version: v1.0.0
 */
public class IotApplication extends Application {

    private static Application application;

    @Override
    public void onCreate() {
        super.onCreate();
        application = this;

        CommonUtils.init(this);

        /**
         * 初始化日志
         */
        Logger.clearLogAdapters();
        FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
                .showThreadInfo(true)
                .methodCount(1)
                .methodOffset(7)
                .tag("IoT")
                .build();
        Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy));

        initGreenDao();

        WCHUARTManager.getInstance().init(this);
    }

    private void initGreenDao() {
        DaoManager mManager = DaoManager.getInstance();
        mManager.init(this);
    }

    public static Context getContext() {
        return application;
    }

}